package org.forum.chat.privatechat.serverpoint;

import java.util.ArrayList;
import java.util.List;

/**
 * 用于保存存放在内存中的聊天记录数(暂未实现持久化至数据库)
 * @author One
 *
 */
public class Transcript {
	
	private List<String> messages = new ArrayList<>();
	
	private List<String> usernames = new ArrayList<>();
	
	//默认保存聊天记录为50行
	private int maxLines = 50;
	//当前包能够调用
	Transcript(){}
	
	Transcript(int maxLines){
		this.maxLines = maxLines;
	}
	
	public String getLastUsername(){
		return usernames.get(usernames.size()-1);
	}
	
	public String getLastMessage(){
		return messages.get(0);
	}
	
	public void addEntry(String username, String message){
		if(usernames.size()>maxLines){
			usernames.remove(0);
			messages.remove(0);
		}
		usernames.add(username);
		messages.add(message);
	}

}
